import { NextRequest, userAgent, NextResponse } from 'next/server'
// This function can be marked `async` if using `await` inside
export default function middleware(request: NextRequest) {
  // 1.上报日志
  if (request.nextUrl.pathname) {
    const ua = userAgent(request)
    console.log(1, request.nextUrl.href);
    console.log(2, request.referrer);
    console.log(3, request.geo);
    console.log(4, ua);
    // 接口上报
  }

  // 2.重定向
  if (request.nextUrl.pathname === '/info') {
    return NextResponse.redirect(new URL('/', request.url));
  }
}

// See "Matching Paths" below to learn more
export const config = {
  matcher: ['/info', '/']
}